package com.cxs.musicplaywidget.data;

import com.cxs.musicplaywidget.player.data.MusicData;
import com.cxs.musicplaywidget.player.data.MusicInfo;
import com.cxs.musicplaywidget.player.store.MediaStore;

import java.util.List;

public class EventParam implements Cloneable{
    // 要执行的动作
    private EventAction eventAction = null;
    // 设备索引
    private byte deviceIndex = 0;
    // 当前远程设备播放的索引
    private int playIndex = -1;
    // 当前本地设备播放的索引
    private int myPlayIndex = -1;
    // 正在播放
    private boolean isPlaying = false;
    // 当前播放的歌曲信息
    private MusicInfo musicInfo;
    // 歌曲缩略图
    private byte[] thumbnail = null;
    // 歌曲数据
    private MusicData musicData = null;
    // 最大音量
    private int maxVolume;
    // 当前音量
    private int volume;
    // 播放列表
    private List<MusicInfo> playList = null;
    // 播放状态
    private PlayerState playerState = null;


    public EventParam() {
    }

    public EventParam(EventAction eventAction) {
        this.eventAction = eventAction;
    }

    public EventParam(EventAction eventAction, byte deviceIndex) {
        this.eventAction = eventAction;
        this.deviceIndex = deviceIndex;
    }

    public EventParam(EventAction eventAction, int playIndex) {
        this.eventAction = eventAction;
        this.playIndex = playIndex;
    }

    public EventParam(EventAction eventAction, PlayerState playerState) {
        this.eventAction = eventAction;
        this.playerState = playerState;
    }

    public EventParam(EventAction eventAction, List<MusicInfo> playList) {
        this.eventAction = eventAction;
        this.playList = playList;
    }

    public EventAction getEventAction() {
        return eventAction;
    }

    public void setEventAction(EventAction eventAction) {
        this.eventAction = eventAction;
    }

    public int getDeviceIndex() {
        return deviceIndex;
    }

    public void setDeviceIndex(byte deviceIndex) {
        this.deviceIndex = deviceIndex;
    }

    public int getPlayIndex() {
        return playIndex;
    }

    public void setPlayIndex(int playIndex) {
        this.playIndex = playIndex;
    }

    public int getMyPlayIndex() {
        return myPlayIndex;
    }

    public void setMyPlayIndex(int myPlayIndex) {
        this.myPlayIndex = myPlayIndex;
    }

    public boolean isPlaying() {
        return isPlaying;
    }

    public void setPlaying(boolean playing) {
        isPlaying = playing;
    }

    public int getMaxVolume() {
        return maxVolume;
    }

    public void setMaxVolume(int maxVolume) {
        this.maxVolume = maxVolume;
    }

    public int getVolume() {
        return volume;
    }

    public void setVolume(int volume) {
        this.volume = volume;
    }

    public List<MusicInfo> getPlayList() {
        return playList;
    }

    public MusicInfo getMusicInfo() {
        return musicInfo;
    }

    public void setMusicInfo(MusicInfo musicInfo) {
        this.musicInfo = musicInfo;
    }

    public void setPlayList(List<MusicInfo> playList) {
        this.playList = playList;
    }

    public PlayerState getPlayerState() {
        return playerState;
    }

    public void setPlayerState(PlayerState playerState) {
        this.playerState = playerState;
    }

    public byte[] readThumbnail() {
        return thumbnail;
    }

    public void writeThumbnail(byte[] thumbnail) {
        this.thumbnail = thumbnail;
    }

    public MusicData getMusicData() { return musicData; }

    public void setMusicData(MusicData data) {
        this.musicData = data;
    }

    public EventParam dup() {
        try {
            return (EventParam)this.clone();
        } catch (CloneNotSupportedException e) {
            return null;
        }
    }

    @Override
    public String toString() {
        return "EventParam{" +
                "eventAction=" + eventAction +
                ", deviceIndex=" + deviceIndex +
                ", playIndex=" + playIndex +
                ", myPlayIndex=" + myPlayIndex +
                ", playList=" + playList +
                ", playerState=" + playerState +
                ", thumbnail=" + thumbnail +
                '}';
    }

    public enum PlayerState {
        NONE,
        PREPARED,
        /**
         * 播放状态
         */
        PLAYING,
        /**
         * 暂停状态
         */
        PAUSED;

    }

    public enum EventAction {
        ISPLAYING(99),
        PLAY(100),
        PAUSE(101),
        PREVIOUS(102),
        NEXT(103),
        LOAD_DEVICE_LIST(104),
        GET_PLAYER_STATE(105),
        GET_PLAY_LIST(106),
        DEVICE_CHANGED(107),
        CONNECT(108),
        CONNECTING(109),
        CONNECTED(110),
        GET_MUSIC_INFO(111),
        IF_CONNECTED(112),
        RANDOM(113),
        LOOP(114),
        DECREASE(115),
        INCREASE(116),
        GET_VOLUME(117),
        GET_MUSIC_DATA(118),
        GET_THUMBNAIL(119),
        RELOAD_PLAY_LIST(120);

        private final int code;

        EventAction(int code) {
            this.code = code;
        }

        public int getCode() {
            return this.code;
        }

        // 通过value值获取枚举值
        public static EventAction getByValue(int value) {
            for (EventAction eventAction : EventAction.values()) {
                if (eventAction.code == value) {
                    return eventAction;
                }
            }
            throw new IllegalArgumentException("No element matches " + value);
        }
    }
}
